//
//  MainTabBaeController.swift
//  haiTwitter
//
//  Created by mohen on 15/3/13.
//  Copyright (c) 2015年 mohen. All rights reserved.
//

import UIKit

class MainTabBarController: UITabBarController {
    
    @IBOutlet weak var mainTabBar: MainTabBar!

    override func viewDidLoad() {
        super.viewDidLoad()

        // 使用代码添加视图控制器
        addControllers()
        
        weak var weakSelf = self
        mainTabBar.composedButtonClick = {
            println("hello")
            // modal 撰写微博 控制器
            let sb = UIStoryboard(name: "Compose", bundle: nil)
            
            weakSelf!.presentViewController(sb.instantiateInitialViewController() as! UIViewController, animated: true, completion: nil)
        }
        
    }
    
    func addControllers() {
        
        addChildController("Home", "首页", "tabbar_home", "tabbar_home_highlighted")
        addChildController("Message", "消息", "tabbar_message_center", "tabbar_message_center_highlighted")
        addChildController("Discover", "发现", "tabbar_discover", "tabbar_discover_highlighted")
        addChildController("Profile", "我", "tabbar_profile", "tabbar_profile_highlighted")
        
    }
    
    func addChildController(name: String, _ title: String, _ imageName: String, _ highlight: String) {
        
        let sb = UIStoryboard(name: name, bundle: nil)
        let vc = sb.instantiateInitialViewController() as! UINavigationController
        
        // 添加图标和文字
        vc.tabBarItem.image = UIImage(named: imageName)
        vc.tabBarItem.selectedImage = UIImage(named: highlight)
        
        vc.title = title
        
        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.orangeColor()], forState: UIControlState.Selected)
        
        self.addChildViewController(vc)
        
    }
  
}
